<template>
    <h1>操作人员添加</h1>
    <el-form :model="renyuan" label-width="120px">
        <el-form-item label="姓名">
            <el-input v-model="renyuan.adminname" />
        </el-form-item>
    </el-form>
    <el-form :model="renyuan" label-width="120px">
        <el-form-item label="密码">
            <el-input v-model="renyuan.password" />
        </el-form-item>
    </el-form>
    <el-form :model="renyuan" label-width="120px">
        <el-form-item label="角色">
            <el-radio-group v-model="renyuan.role">
                <el-radio :label="1">超级管理员</el-radio>
                <el-radio :label="2">普通管理员</el-radio>
            </el-radio-group>
        </el-form-item>
    </el-form>
    <el-form-item>
        <el-button type="primary" @click="addrenyuan ">添加</el-button>
    </el-form-item>
</template>
  
<script setup lang="ts">
import { ElMessage } from "element-plus";
import { reactive } from "vue"
import { useRouter } from "vue-router";
import service from "../../../utils/service";

const $router = useRouter()
interface IAdmin {
    "adminname": string,
    "password": string,
    "role": number,//1:表示超级管理员，2：普通管理员
    "checkedKeys": string[]
}

// 当前管理员的数据
const renyuan = reactive<IAdmin>({

    "adminname": "",
    "password": "",
    "role": 1,
    "checkedKeys": []
})
const addrenyuan = () => {
    service({
        url: "/admin/add",
        method: "post",
        data: renyuan
    }).then(res => {
        if (res.data.code === "200") {
            ElMessage({
                message: "添加成功",
                type: "success"
            })
            $router.push("/AdminList")
        }
    })
}
</script>
  
<style></style>